#include <iostream>
using namespace std;

#if 0
//error
void swap1 (int x, int y) {
	x = x ^ y;
	y = x ^ y;
	x = x ^ y;
}
#endif

void swap1 (int *x, int *y) {
	*x = *x ^ *y;
	*y = *x ^ *y;
	*x = *x ^ *y;
}

void swap2 (int& x, int& y) {
	x = x ^ y;
	y = x ^ y;
	x = x ^ y;
}

void swap3 (const char* &str1, const char* &str2)
{
	const char *z = str1;
	str1 = str2;
	str2 = z;
}

int main (void)
{
	int a = 20;
	int b = 10;
	//swap1 (&a, &b);
	swap2 (a, b); //int& x = a; int& y = b;
	cout << "a=" << a << " b=" << b << endl;

	//练习: 通过引用型参数, 实现交换两个 const char * 字符串
	//str1 = "hello"  str2 = "world"
	const char *s1 = "hello";
	const char *s2 = "world";
	swap3 (s1, s2);
	cout << "s1=" << s1 << " s2=" << s2 << endl;
	return 0;
}
